package com.ibeeking.gmc.global.g.rest.controller.v1.feign;


import com.ibeeking.found.common.entity.DatabaseTemplateDTO;
import com.ibeeking.found.common.entity.DatasourceConfigDTO;
import com.ibeeking.found.common.entity.IndustryFrontendDTO;
import com.ibeeking.gmc.global.g.rest.service.IDatabaseTemplateService;
import com.ibeeking.gmc.global.g.rest.service.IDatasourceConfigService;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName TemplateDatabaseController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-03-02 09:07
 **/
@RestController
@RequestMapping("/g/datasource/feign/v1")
public class DatasourceFeignController {

    @Resource
    private IDatasourceConfigService datasourceConfigServiceImpl;

    @Resource
    private IDatabaseTemplateService databaseTemplateServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询数据源配置")
    @PostMapping(value = "/queryDatasourceConfig/{configId}")
    public DatasourceConfigDTO queryDatasourceConfig(@PathVariable("configId") Long configId) {
        return datasourceConfigServiceImpl.viewById(configId);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询租户数据源")
    @PostMapping(value = "/queryTenantDatasource/{tenantId}")
    public DatasourceConfigDTO queryTenantDatasource(@PathVariable("tenantId") Integer tenantId) {
        return datasourceConfigServiceImpl.queryTenantDatasource(tenantId);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询租户数据源")
    @PostMapping(value = "/queryIndustryFrontend/{industry}/{frontend}")
    public List<IndustryFrontendDTO> quertIndustryFrontend(@PathVariable("industry") String industry, @PathVariable("frontend") String frontend) {
        return databaseTemplateServiceImpl.quertIndustryFrontend(industry, frontend);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询模板库")
    @PostMapping(value = "/listTemplateByIndustry/{industry}")
    public List<DatabaseTemplateDTO> listTemplateByIndustry(@PathVariable("industry") String industry) {
        return databaseTemplateServiceImpl.listByIndustry(industry);
    }

}
